package cn.chinaelink.im.mcboot.controller;

import cn.chinaelink.im.mcboot.dto.UserLoginDto;
import cn.chinaelink.im.mcboot.vo.UserVo;
import com.sun.deploy.net.HttpResponse;
import lombok.extern.slf4j.Slf4j;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import org.springframework.http.HttpRequest;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

@Controller
@Slf4j
@RequestMapping("/api")
public class LoginController {

    @PostMapping("/login/account")
    @ResponseBody
    public JSONObject account(@RequestBody UserLoginDto userLoginDto) {
        UserVo userVo = new UserVo();
        if ("ant.design".equals(userLoginDto.getPassword()) || "admin".equals(userLoginDto.getUsername())) {
            userVo.setName("admin");
            userVo.setStatus("ok");
            userVo.setType(userLoginDto.getType());
            userVo.setCurrentAuthority("admin");
            return JSONObject.fromObject(userVo);
        }
        if ("ant.design".equals(userLoginDto.getPassword()) || "user".equals(userLoginDto.getUsername())) {
            userVo.setName("user");
            userVo.setStatus("ok");
            userVo.setType(userLoginDto.getType());
            userVo.setCurrentAuthority("user");
            return JSONObject.fromObject(userVo);
        }
        if ("mobile".equals(userLoginDto.getType())) {
            userVo.setName("admin");
            userVo.setStatus("ok");
            userVo.setType(userLoginDto.getType());
            userVo.setCurrentAuthority("admin");
            return JSONObject.fromObject(userVo);
        }
        userVo.setName("guest");
        userVo.setStatus("error");
        userVo.setType(userLoginDto.getType());
        userVo.setCurrentAuthority("guest");
        return JSONObject.fromObject(userVo);
    }

    @PostMapping("/login/outLogin")
    @ResponseBody
    public JSONObject outLogin() {
        JSONObject data = new JSONObject();
        data.put("data", new JSONObject());
        data.put("success", true);
        return data;
    }

    @RequestMapping("/currentUser")
    @ResponseBody
    public JSONObject currentUser(){
        JSONObject data = new JSONObject();
        data.put("name", "杜燕军");
        data.put("access", "admin");
        data.put("avatar", "https://gw.alipayobjects.com/zos/antfincdn/XAosXuNZyF/BiazfanxmamNRoxxVxka.png");
        data.put("userid", "00000001");
        data.put("email", "antdesign@alipay.com");
        data.put("signature", "海纳百川，有容乃大");
        data.put("title", "交互专家");
        data.put("group", "蚂蚁金服－某某某事业群－某某平台部－某某技术部－UED");

        JSONArray tagArray = new JSONArray();
        JSONObject tag0 = new JSONObject();
        tag0.put("key", "0");
        tag0.put("label", "很有想法的");
        tagArray.add(tag0);

        JSONObject tag1 = new JSONObject();
        tag1.put("key", "1");
        tag1.put("label", "专注设计");
        tagArray.add(tag1);

        JSONObject tag2 = new JSONObject();
        tag2.put("key", "2");
        tag2.put("label", "辣~");
        tagArray.add(tag2);

        JSONObject tag3 = new JSONObject();
        tag3.put("key", "3");
        tag3.put("label", "大长腿");
        tagArray.add(tag3);

        JSONObject tag4 = new JSONObject();
        tag4.put("key", "4");
        tag4.put("label", "川妹子");
        tagArray.add(tag4);

        JSONObject tag5 = new JSONObject();
        tag5.put("key", "5");
        tag5.put("label", "海纳百川");
        tagArray.add(tag5);
        data.put("tags", tagArray);

        data.put("notifyCount", 12);
        data.put("unreadCount", 11);
        data.put("country", "China");

        JSONObject geographic = new JSONObject();
        JSONObject province = new JSONObject();
        province.put("key", "330000");
        province.put("label", "浙江省");
        geographic.put("province", province);
        JSONObject city = new JSONObject();
        city.put("key", "330100");
        city.put("label", "杭州市");
        geographic.put("city", city);

        data.put("geographic", geographic);
        data.put("address", "西湖区工专路 77 号");
        data.put("phone", "0752-268888888");

        JSONObject body = new JSONObject();
        body.put("data", data);
        body.put("success", true);
        return body;
    }

    @RequestMapping("/notices")
    @ResponseBody
    public JSONObject notices(){
        JSONObject data = new JSONObject();
        JSONArray dataArray = new JSONArray();
        JSONObject notice1 = new JSONObject();
        notice1.put("id","000000001");
        notice1.put("avatar","https://gw.alipayobjects.com/zos/rmsportal/ThXAXghbEsBCCSDihZxY.png");
        notice1.put("title","你收到了 14 份新周报");
        notice1.put("datetime","2017-08-09");
        notice1.put("type","notification");
        dataArray.add(notice1);

        JSONObject notice2 = new JSONObject();
        notice2.put("id","000000002");
        notice2.put("avatar","https://gw.alipayobjects.com/zos/rmsportal/OKJXDXrmkNshAMvwtvhu.png");
        notice2.put("title","你推荐的 曲妮妮 已通过第三轮面试");
        notice2.put("datetime","2017-08-08");
        notice2.put("type","notification");
        dataArray.add(notice2);

        JSONObject notice3 = new JSONObject();
        notice3.put("id","000000003");
        notice3.put("avatar","https://gw.alipayobjects.com/zos/rmsportal/kISTdvpyTAhtGxpovNWd.png");
        notice3.put("title","这种模板可以区分多种通知类型");
        notice3.put("datetime","2017-08-07");
        notice3.put("type","notification");
        dataArray.add(notice3);

        JSONObject notice4 = new JSONObject();
        notice4.put("id","000000004");
        notice4.put("avatar","https://gw.alipayobjects.com/zos/rmsportal/GvqBnKhFgObvnSGkDsje.png");
        notice4.put("title","这种模板可以区分多种通知类型");
        notice4.put("datetime","2017-08-07");
        notice4.put("type","notification");
        dataArray.add(notice4);

        JSONObject notice5 = new JSONObject();
        notice5.put("id","000000005");
        notice5.put("avatar","https://gw.alipayobjects.com/zos/rmsportal/ThXAXghbEsBCCSDihZxY.png");
        notice5.put("title","内容不要超过两行字，超出时自动截断");
        notice5.put("datetime","2017-08-07");
        notice5.put("type","notification");
        dataArray.add(notice5);

        JSONObject notice6 = new JSONObject();
        notice6.put("id","000000006");
        notice6.put("avatar","https://gw.alipayobjects.com/zos/rmsportal/fcHMVNCjPOsbUGdEduuv.jpeg");
        notice6.put("title","曲丽丽 评论了你");
        notice6.put("description","描述信息描述信息描述信息");
        notice6.put("datetime","2017-08-07");
        notice6.put("type","message");
        notice6.put("clickClose",true);
        dataArray.add(notice6);

        JSONObject notice7 = new JSONObject();
        notice7.put("id","000000007");
        notice7.put("avatar","https://gw.alipayobjects.com/zos/rmsportal/fcHMVNCjPOsbUGdEduuv.jpeg");
        notice7.put("title","朱偏右 回复了你");
        notice7.put("description","这种模板用于提醒谁与你发生了互动，左侧放『谁』的头像");
        notice7.put("datetime","2017-08-07");
        notice7.put("type","message");
        notice7.put("clickClose",true);
        dataArray.add(notice7);

        JSONObject notice8 = new JSONObject();
        notice8.put("id","000000008");
        notice8.put("avatar","https://gw.alipayobjects.com/zos/rmsportal/fcHMVNCjPOsbUGdEduuv.jpeg");
        notice8.put("title","标题");
        notice8.put("description","这种模板用于提醒谁与你发生了互动，左侧放『谁』的头像");
        notice8.put("datetime","2017-08-07");
        notice8.put("type","message");
        notice8.put("clickClose",true);
        dataArray.add(notice8);

        JSONObject notice9 = new JSONObject();
        notice9.put("id","000000009");
        notice9.put("title","任务名称");
        notice9.put("description","任务需要在 2017-01-12 20:00 前启动");
        notice9.put("extra","未开始");
        notice9.put("status","todo");
        notice9.put("type","'event");
        dataArray.add(notice9);

        JSONObject notice10 = new JSONObject();
        notice10.put("id","000000010");
        notice10.put("title","第三方紧急代码变更");
        notice10.put("description","冠霖提交于 2017-01-06，需在 2017-01-07 前完成代码变更任务");
        notice10.put("extra","马上到期");
        notice10.put("status","urgent");
        notice10.put("type","'event");
        dataArray.add(notice10);

        JSONObject notice11 = new JSONObject();
        notice11.put("id","000000011");
        notice11.put("title","信息安全考试");
        notice11.put("description","指派竹尔于 2017-01-09 前完成更新并发布");
        notice11.put("extra","已耗时 8 天");
        notice11.put("status","doing");
        notice11.put("type","'event");
        dataArray.add(notice11);

        JSONObject notice12 = new JSONObject();
        notice12.put("id","000000012");
        notice12.put("title","ABCD 版本发布");
        notice12.put("description","冠霖提交于 2017-01-06，需在 2017-01-07 前完成代码变更任务");
        notice12.put("extra","进行中");
        notice12.put("status","processing");
        notice12.put("type","'event");
        dataArray.add(notice12);

        data.put("data",dataArray);
        return data;
    }

    @RequestMapping("/getUserMenus")
    @ResponseBody
    public JSONObject getUserMenus(){
        JSONArray dataArray = new JSONArray();
        JSONObject menu1 = new JSONObject();
        menu1.put("path","/user");
        menu1.put("layout",false);

        JSONArray routeArray1 = new JSONArray();
        JSONObject route11 = new JSONObject();
        route11.put("path", "/user/login");
        route11.put("layout", false);
        route11.put("name", "login");
        route11.put("component", "./user/Login");
        routeArray1.add(route11);

        JSONObject route12 = new JSONObject();
        route12.put("path", "/user");
        route12.put("redirect", "/user/login");
        routeArray1.add(route12);

        JSONObject route13 = new JSONObject();
        route13.put("name", "register-result");
        route13.put("icon", "smile");
        route13.put("path", "/user/register-result");
        route13.put("component", "./user/register-result");
        routeArray1.add(route13);

        JSONObject route14 = new JSONObject();
        route14.put("name", "register");
        route14.put("icon", "smile");
        route14.put("path", "/user/register");
        route14.put("component", "./user/register");
        routeArray1.add(route14);

        JSONObject route15 = new JSONObject();
        route15.put("component", "404");
        routeArray1.add(route15);

        menu1.put("routes",routeArray1);
        dataArray.add(menu1);


        JSONObject menu2 = new JSONObject();
        menu2.put("path","/dashboard");
        menu2.put("name","dashboard");
        menu2.put("icon","dashboard");

        JSONArray routeArray2 = new JSONArray();
        JSONObject route21 = new JSONObject();
        route21.put("path", "/dashboard");
        route21.put("redirect", "/dashboard/analysis");
        routeArray2.add(route21);

        JSONObject route22 = new JSONObject();
        route22.put("name", "analysis");
        route22.put("icon", "smile");
        route22.put("path", "/dashboard/analysis");
        route22.put("component", "./dashboard/analysis");
        routeArray2.add(route22);

        JSONObject route23 = new JSONObject();
        route23.put("name", "monitor");
        route23.put("icon", "smile");
        route23.put("path", "/dashboard/monitor");
        route23.put("component", "./dashboard/monitor");
        routeArray2.add(route23);

        JSONObject route24 = new JSONObject();
        route24.put("name", "workplace");
        route24.put("icon", "smile");
        route24.put("path", "/dashboard/workplace");
        route24.put("component", "./dashboard/workplace");
        routeArray2.add(route24);

        JSONObject route25 = new JSONObject();
        route25.put("name", "demo1");
        route25.put("icon", "smile");
        route25.put("path", "/dashboard/demo1");
        route25.put("component", "./demo/demo1");
        routeArray2.add(route25);
        menu2.put("routes",routeArray2);
        dataArray.add(menu2);

        JSONObject menu3 = new JSONObject();
        menu3.put("path","/form");
        menu3.put("icon","form");
        menu3.put("name","form");

        JSONArray routeArray3 = new JSONArray();
        JSONObject route31 = new JSONObject();
        route31.put("path", "/form");
        route31.put("redirect", "/form/basic-form");
        routeArray3.add(route31);

        JSONObject route32 = new JSONObject();
        route32.put("name", "basic-form");
        route32.put("icon", "smile");
        route32.put("path", "/form/basic-form");
        route32.put("component", "./form/basic-form");
        routeArray3.add(route32);

        menu3.put("routes",routeArray3);
        dataArray.add(menu3);

        JSONObject menu10 = new JSONObject();
        menu10.put("path","/");
        menu10.put("redirect","/dashboard/analysis");
        dataArray.add(menu10);

        JSONObject menu11 = new JSONObject();
        menu11.put("component","404");
        dataArray.add(menu11);

        JSONObject body = new JSONObject();
        body.put("success", true);
        body.put("data", dataArray);
        return body;
    }
}
